/**
 * @file Table_Driven_04.c
 * 
 * @brief 
 *          通过表格驱动的方式实现SIP消息处理
 */

typedef void (*SIP_MSG_FUN)(const char *);

typedef struct __msg_fun_st
{
    const char *msg_type;   // 消息类型
    SIP_MSG_FUN fun_ptr;    // 函数处理
} msg_fun_st;

msg_fun_st msg_flow[] =
{
    {"invite", invite_fun},
    {"ring_100", tring_fun},
    {"ring_180", tring_180_fun},
    {"ring_181", ring_181_fun},
    {"ring_182", ring_182_fun},
    {"ring_183", ring_183_fun},
    {"ok_200", ok_200_fun},
    ...
    {"fail_486", fail_486_fun},
};

void msg_proc(const char *msg_type, const char *msg_buf)
{
    int type_num = sizeof(msg_flow) / sizeof(msg_fun_st);
    int i = 0;

    for (i = 0; i < type_num; i++)
    {
        if (0 == strcmp(msg_flow[i].msg_type, msg_type))
        {
            msg_flow[i].fun_ptr(msg_buf);
            return;
        }
    }

    printf("未知的消息类型%s\n", msg_type);
}
